
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>2.1 Processor · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="22-pipline.html" />
    
    
    <link rel="prev" href="../2ji-ben-zu-jian.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    序言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1.html">
            
                <a href="../chapter1.html">
            
                    
                    1. 快速入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../2ji-ben-zu-jian.html">
            
                <a href="../2ji-ben-zu-jian.html">
            
                    
                    2.基本组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.3.1" data-path="processor.html">
            
                <a href="processor.html">
            
                    
                    2.1 Processor
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="22-pipline.html">
            
                <a href="22-pipline.html">
            
                    
                    2.2 Pipline
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="23-sessionpool.html">
            
                <a href="23-sessionpool.html">
            
                    
                    2.3 SessionPool
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../3pa-chong-kong-zhi.html">
            
                <a href="../3pa-chong-kong-zhi.html">
            
                    
                    3.爬虫控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../4chou-qu-qi.html">
            
                <a href="../4chou-qu-qi.html">
            
                    
                    4.抽取器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../4chou-qu-qi/41sipsoup.html">
            
                <a href="../4chou-qu-qi/41sipsoup.html">
            
                    
                    4.1SipSoup
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../4chou-qu-qi/42tableevaluator.html">
            
                <a href="../4chou-qu-qi/42tableevaluator.html">
            
                    
                    4.2TableEvaluator
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../5zhong-zi-guan-li-qi.html">
            
                <a href="../5zhong-zi-guan-li-qi.html">
            
                    
                    5.种子管理器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../6shi-jian-xun-huan.html">
            
                <a href="../6shi-jian-xun-huan.html">
            
                    
                    6.事件循环
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../6shi-jian-xun-huan/61-eventloopgong-zuo-ji-zhi.html">
            
                <a href="../6shi-jian-xun-huan/61-eventloopgong-zuo-ji-zhi.html">
            
                    
                    6.1 eventLoop工作机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../6shi-jian-xun-huan/62zi-dong-shi-jian.html">
            
                <a href="../6shi-jian-xun-huan/62zi-dong-shi-jian.html">
            
                    
                    6.2 自动事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../6shi-jian-xun-huan/63delayevent.html">
            
                <a href="../6shi-jian-xun-huan/63delayevent.html">
            
                    
                    6.3 延时事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../6shi-jian-xun-huan/64classScanner.html">
            
                <a href="../6shi-jian-xun-huan/64classScanner.html">
            
                    
                    6.4 classScanner
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >2.1 Processor</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>VS&#x4E2D;&#x7684;Processor&#x5408;&#x5E76;&#x4E86;&#x9875;&#x9762;&#x4E0B;&#x8F7D;&#x903B;&#x8F91;&#x548C;&#x9875;&#x9762;&#x89E3;&#x6790;&#x903B;&#x8F91;&#xFF0C;&#x5728;VS&#x7406;&#x5FF5;&#x4E2D;&#xFF0C;&#x4E00;&#x6B21;&#x8D44;&#x6E90;&#x7684;&#x83B7;&#x53D6;&#x53EF;&#x4EE5;&#x6D89;&#x53CA;&#x591A;&#x6B21;&#x7F51;&#x7EDC;&#x4EA4;&#x4E92;&#xFF0C;&#x6240;&#x4EE5;VS&#x7684;Processor&#x786E;&#x5207;&#x7684;&#x547D;&#x540D;&#x662F;&#xFF1A; SeedProcessor,&#x5176;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code>public interface SeedProcessor {
    void process(Seed seed, CrawlerSession crawlerSession, CrawlResult crawlResult);
}
</code></pre><p>SeedProcessor&#x5305;&#x542B;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5206;&#x522B;&#x662F;seed&#x4EE3;&#x8868;&#x79CD;&#x5B50;&#xFF1B;crawlerSession&#x4EE3;&#x8868;&#x7528;&#x6237;&#x7684;&#x4F1A;&#x8BDD;&#xFF0C;crawlResult&#x4EE3;&#x8868;&#x6293;&#x53D6;&#x7ED3;&#x679C;&#x3002;</p>
<h3 id="seed">seed</h3>
<p>&#x901A;&#x4FD7;&#x6765;&#x8BF4;&#x5C31;&#x662F;&#x8FD9;&#x6B21;&#x5904;&#x7406;&#x7684;&#x4EFB;&#x52A1;&#x4FE1;&#x606F;&#xFF0C;&#x4E00;&#x822C;&#x6765;&#x8BF4;&#x5C31;&#x662F;&#x94FE;&#x63A5;&#x4FE1;&#x606F;&#xFF08;URL&#xFF09;&#x3002;&#x4F46;&#x662F;&#x5BF9;&#x4E8E;VS&#x6765;&#x8BF4;&#xFF0C;seed&#x53EF;&#x4EE5;&#x4E0D;&#x662F;URL&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;ID&#xFF0C;&#x4E00;&#x4E2A;&#x9875;&#x7801;&#x7B49;&#x7B49;&#x3002;&#x5BF9;&#x4E8E;&#x5782;&#x76F4;&#x722C;&#x866B;&#x6765;&#x8BF4;&#xFF0C;&#x4E0D;&#x80FD;&#x9650;&#x5B9A;&#x6293;&#x53D6;&#x7684;&#x8F93;&#x5165;&#x5C31;&#x662F;URL&#x7684;&#x3002;&#x53E6;&#x4E00;&#x65B9;&#x9762;&#xFF0C;seed&#x5305;&#x542B;data&#x5B57;&#x6BB5;&#xFF0C;&#x7C7B;&#x578B;&#x662F;String&#x3002;&#x539F;&#x56E0;&#x662F;&#x6211;&#x89C9;&#x5F97;seed&#x662F;&#x9700;&#x8981;&#x53EF;&#x5E8F;&#x5217;&#x5316;&#x7684;&#xFF0C;&#x53EA;&#x8981;&#x662F;&#x53EF;&#x4EE5;&#x5E8F;&#x5217;&#x5316;&#x7684;&#x4E1C;&#x897F;&#x90FD;&#x53EF;&#x4EE5;&#x7528;&#x5B57;&#x7B26;&#x4E32;&#x8868;&#x793A;&#x3002;&#x50CF;webMagic&#x8FD9;&#x79CD;&#x5BB9;&#x6613;&#x5F15;&#x8D77;&#x7406;&#x89E3;&#x8BEF;&#x5DEE;&#xFF0C;&#x540C;&#x65F6;&#x4E5F;&#x5BB9;&#x6613;&#x5F15;&#x53D1;&#x5E8F;&#x5217;&#x5316;&#x7684;bug&#x3002;&#x4E2A;&#x4EBA;&#x89C9;&#x5F97;&#x5C01;&#x88C5;&#x6210;requestBody&#x662F;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#x7684;&#x3002;</p>
<p>seed&#x6709;&#x5982;&#x4E0B;&#x529F;&#x80FD;&#xFF1A;</p>
<ol>
<li>data&#xFF1A;&#x5B58;&#x50A8;&#x79CD;&#x5B50;&#x539F;&#x59CB;&#x4FE1;&#x606F;&#xFF0C;&#x4E00;&#x822C;&#x662F;URL&#x6587;&#x672C;</li>
<li>retry:&#x8BB0;&#x5F55;&#x5F53;&#x524D;&#x91CD;&#x8BD5;&#x6B21;&#x6570;</li>
<li>status&#xFF1A;&#x5F53;&#x524D;&#x79CD;&#x5B50;&#x72B6;&#x6001;&#xFF0C;&#x5305;&#x62EC;&#x521D;&#x59CB;&#x5316;&#x3001;&#x6210;&#x529F;&#x3001;&#x5931;&#x8D25;&#x3001;&#x91CD;&#x8BD5;&#x3001;&#x8FD0;&#x884C;&#x4E2D;</li>
<li>maxRetry&#xFF1A;&#x5F53;&#x524D;&#x79CD;&#x5B50;&#x6700;&#x5927;&#x91CD;&#x8BD5;&#x6B21;&#x6570;&#xFF0C;&#x4F60;&#x6CA1;&#x6709;&#x770B;&#x9519;&#xFF0C;VS&#x5BF9;&#x4E8E;&#x79CD;&#x5B50;&#x91CD;&#x8BD5;&#x6B21;&#x6570;&#x7684;&#x8BBE;&#x7F6E;&#xFF0C;&#x53EF;&#x4EE5;&#x7CBE;&#x786E;&#x5230;&#x6BCF;&#x4E2A;&#x79CD;&#x5B50;&#x7684;&#x7C92;&#x5EA6;</li>
<li>ignore:&#x5F53;&#x5728;processor&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5982;&#x679C;&#x53D1;&#x73B0;&#x79CD;&#x5B50;&#x662F;&#x4E0D;&#x5408;&#x6CD5;&#x7684;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x7F6E;&#x6B21;&#x6807;&#x5FD7;&#x4F4D;&#x3002;&#x8FD9;&#x6837;VS&#x5C06;&#x4E0D;&#x4F1A;&#x5BF9;&#x8FD9;&#x4E2A;&#x79CD;&#x5B50;&#x6267;&#x884C;&#x91CD;&#x8BD5;&#x64CD;&#x4F5C;</li>
<li>activeTimeStamp&#xFF1A;&#x5F53;&#x524D;&#x79CD;&#x5B50;&#x751F;&#x6548;&#x65F6;&#x95F4;&#xFF0C;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x5F53;&#x524D;&#x79CD;&#x5B50;&#x5728;&#x90A3;&#x4E2A;&#x65F6;&#x95F4;&#x70B9;&#x8FDB;&#x884C;&#x6293;&#x53D6;&#xFF0C;&#x5982;&#x8BBE;&#x5B9A;&#x5728;&#x4E09;&#x5929;&#x540E;&#xFF0C;&#x90A3;&#x4E48;&#x4E09;&#x5929;&#x540E;&#x624D;&#x4F1A;&#x5BF9;&#x8FD9;&#x4E2A;&#x79CD;&#x5B50;&#x8FDB;&#x884C;&#x8C03;&#x5EA6;&#x3002;&#x5173;&#x4E8E;&#x5EF6;&#x65F6;&#x79CD;&#x5B50;&#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;&#xFF0C;&#x8BF7;&#x5173;&#x6CE8;seedManager&#x76F8;&#x5173;&#x6587;&#x6863;</li>
<li>segmentKey&#xFF1A;&#x5206;&#x6BB5;&#x6807;&#x8BC6;VS&#x5185;&#x90E8;&#x4F7F;&#x7528;&#xFF0C;&#x975E;&#x5E38;&#x4E0D;&#x5EFA;&#x8BAE;&#x7528;&#x6237;&#x7AEF;&#x64CD;&#x4F5C;&#x8FD9;&#x4E2A;&#x5B57;&#x6BB5;&#x7684;&#x503C;</li>
<li>ext&#xFF1A;&#x6269;&#x5C55;&#x4FE1;&#x606F;&#xFF0C;&#x53EF;&#x7531;&#x7528;&#x6237;&#x81EA;&#x884C;&#x6269;&#x5C55;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;hashMap&#xFF0C;key-value&#x5747;&#x4E3A;String</li>
</ol>
<h2 id="crawlersession">crawlerSession</h2>
<p>crawlerSession&#x662F;&#x7F51;&#x7EDC;&#x5C42;&#x5305;&#x88C5;&#xFF0C;&#x5C31;&#x4EE3;&#x8868;&#x4E00;&#x4E2A;&#x6D4F;&#x89C8;&#x5668;&#x5BF9;&#x8C61;&#xFF0C;&#x4ED6;&#x662F;&#x53EF;&#x590D;&#x7528;&#x7684;&#xFF0C;&#x7531;VS&#x6846;&#x67B6;&#x6240;&#x7BA1;&#x7406;&#xFF0C;&#x5C5E;&#x4E8E;&#x722C;&#x866B;&#x6846;&#x67B6;&#x7684;&#x8D44;&#x6E90;&#x3002;&#x4E00;&#x822C;&#x6765;&#x8BF4;&#xFF0C;crawlerSession&#x7684;&#x4E2A;&#x6570;&#x662F;&#x6709;&#x9650;&#x5236;&#x7684;&#xFF0C;&#x7279;&#x522B;&#x662F;&#x9700;&#x8981;&#x767B;&#x5F55;&#x7684;&#x573A;&#x666F;&#xFF0C;&#x90A3;&#x4E48;&#x6709;&#x591A;&#x5C11;&#x4E2A;&#x8D26;&#x53F7;&#x6700;&#x591A;&#x80FD;&#x591F;&#x5B58;&#x5728;&#x591A;&#x5C11;&#x4E2A;crawlerSession&#x3002;&#x5BF9;&#x4E8E;crawlerSession&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x64CD;&#x4F5C;&#x7684;&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</p>
<ol>
<li>cookieStore: cookie&#x6570;&#x636E;&#xFF0C;&#x662F;httpclient&#x5BF9;&#x5E94;&#x7684;cookieStore&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x60F3;&#x64CD;&#x4F5C;cookie&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x5728;seed&#x91CC;&#x9762;&#x653E;ext&#x4FE1;&#x606F;&#xFF0C;&#x76F4;&#x63A5;&#x64CD;&#x4F5C;cookieStore&#x5373;&#x53EF;&#x3002;</li>
<li>crawlerHttpClient&#xFF1A;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;httpclient&#x5BF9;&#x8C61;&#xFF0C;&#x5C5E;&#x4E8E;<a href="http://git.oschina.net/virjar/proxyipcenter" target="_blank">dungproxy</a>&#x7684;&#x77E5;&#x8BC6;,&#x4ED6;&#x5C5E;&#x4E8E;closeableHttpClient&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x5F53;&#x505A;&#x666E;&#x901A;&#x7684;httpClient&#x5BF9;&#x8C61;&#x4F7F;&#x7528;&#xFF08;&#x8FD9;&#x662F;&#x5B8C;&#x5168;&#x517C;&#x5BB9;&#x7684;&#xFF09;&#x3002;&#x540C;&#x65F6;&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x5927;&#x5BB6;&#x4F7F;&#x7528;&#xFF0C;&#x5979;&#x6709;&#x5C01;&#x88C5;&#x4E86;&#x591A;&#x4E2A;&#x65B9;&#x4FBF;&#x7684;&#x65B9;&#x6CD5;&#x3002;&#x5177;&#x4F53;&#x6587;&#x6863;<a href="http://git.oschina.net/virjar/proxyipcenter/blob/master/doc/client/userGuide/crawler_httpclient.md" target="_blank">crawlerHttpClient </a> &#x76F8;&#x4FE1;&#x4F60;&#x4F1A;&#x5BF9;&#x5979;&#x7231;&#x4E0D;&#x91CA;&#x624B;&#x7684;&#x3002;&#x53E6;&#x5916;&#xFF0C;crawlerHttpClient&#x5185;&#x90E8;&#x7684;cookieStore&#x548C;&#x7B2C;&#x4E00;&#x6761;&#x63D0;&#x5230;&#x7684;cookieStore&#x662F;&#x540C;&#x4E00;&#x4E2A;</li>
<li>ipPool&#xFF1A;&#x4EE3;&#x7406;&#x6C60;&#x5BF9;&#x8C61;&#xFF0C;&#x4EE3;&#x7406;&#x6C60;&#x5BF9;&#x8C61;&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7684;&#x8BBE;&#x8BA1;&#xFF0C;&#x76EE;&#x524D;&#x9ED8;&#x8BA4;&#x5B9E;&#x73B0;&#x662F;&#x8DEF;&#x7531;&#x81F3;dungproxy&#xFF0C;&#x56E0;&#x4E3A;dungproxy&#x4EE3;&#x7406;&#x6C60;&#x5C01;&#x88C5;&#x5F88;&#x5F3A;&#x5927;&#xFF08;dungpoxy-client&#x7684;&#x4EE3;&#x7801;&#x91CF;&#x90FD;&#x5DF2;&#x7ECF;&#x63A5;&#x8FD1;VS-core&#x4E86;&#xFF0C;&#x91CC;&#x9762;&#x5B58;&#x5728;&#x7684;&#x7B97;&#x6CD5;&#x63A7;&#x5236;&#x4E5F;&#x662F;&#x5F88;&#x725B;&#x903C;&#x7684;&#xFF09;&#x3002;&#x5F53;&#x7136;&#xFF0C;&#x4F60;&#x5B8C;&#x5168;&#x53EF;&#x4EE5;&#x66FF;&#x6362;&#x6389;&#x5B83;</li>
<li>proxyStrategy&#xFF1A;&#x4EE3;&#x7406;&#x7B56;&#x7565;&#xFF0C;&#x4EE3;&#x7406;&#x7B56;&#x7565;&#x662F;&#x6307;&#x4F60;&#x60F3;&#x4F7F;&#x7528;&#x4EE3;&#x7406;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x76EE;&#x524D;&#x5305;&#x62EC;&#x6BCF;&#x6B21;&#x90FD;&#x6362;IP&#x3001;&#x6BCF;&#x6B21;processor&#x5904;&#x7406;&#x7684;&#x65F6;&#x5019;&#x66F4;&#x6362;&#x4E00;&#x6B21;IP&#x3001;&#x6BCF;&#x4E2A;&#x7528;&#x6237;&#x767B;&#x5F55;&#x7684;&#x65F6;&#x5019;&#x66F4;&#x6362;&#x4E00;&#x6B21;IP&#x3001;&#x4E0D;&#x4EE3;&#x7406;&#x3001;&#x81EA;&#x5B9A;&#x4E49;&#x4EE3;&#x7406;&#x65B9;&#x5F0F;&#x3002;&#x5F53;&#x7136;&#x9ED8;&#x8BA4;&#x503C;&#x662F;&#x4E0D;&#x4EE3;&#x7406;&#x3002;&#x5BF9;&#x4E8E;&#x81EA;&#x5B9A;&#x4E49;&#x4EE3;&#x7406;&#x65B9;&#x5F0F;&#xFF0C;&#x4F60;&#x53EA;&#x9700;&#x8981;&#x5B9E;&#x73B0;proxyPlanner&#x63A5;&#x53E3;&#x5373;&#x53EF;&#xFF0C;&#x4E2A;&#x4EBA;&#x89C9;&#x5F97;&#x8FD9;&#x79CD;&#x573A;&#x666F;&#x4E0D;&#x591A;&#xFF0C;&#x4F46;&#x662F;&#x8FD8;&#x662F;&#x63D0;&#x4F9B;&#x652F;&#x6301;</li>
<li>proxyPlanner&#xFF1A;&#x4EE3;&#x7406;&#x51B3;&#x5B9A;&#x5668;&#xFF0C;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x4EE3;&#x7406;&#x7B56;&#x7565;&#x7684;&#x5177;&#x4F53;&#x5B9E;&#x73B0;Proxy&#xFF0C;&#x4ED6;&#x7684;&#x7B7E;&#x540D;&#x5982;&#x4E0B;<pre><code>public interface ProxyPlanner {
   /**
    * &#x81EA;&#x5B9A;&#x4E49;&#x4EE3;&#x7406;&#x89C4;&#x5219;,&#x5982;&#x679C;&#x89C9;&#x5F97;&#x9ED8;&#x8BA4;&#x7684;&#x4E09;&#x79CD;&#x7B56;&#x7565;(&#x6BCF;&#x6B21;&#x8BF7;&#x6C42;&#x6362;&#x4EE3;&#x7406;,&#x6BCF;&#x4E2A;session&#x6362;&#x4EE3;&#x7406;,&#x6BCF;&#x4E2A;&#x7528;&#x6237;&#x5207;&#x6362;&#x4EE3;&#x7406;)&#x4E0D;&#x591F;&#x4F7F;&#x7528;,&#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#x4EE3;&#x7406;&#x7B56;&#x7565;
    * 
    * @param host &#x8BF7;&#x6C42;&#x76EE;&#x6807;&#x4E3B;&#x673A;
    * @param request &#x8BF7;&#x6C42;&#x4F53;
    * @param context &#x8BF7;&#x6C42;&#x7684;context
    * @param ipPool &#x4EE3;&#x7406;&#x6C60;&#x5BF9;&#x8C61;,&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x4E00;&#x4E2A;IP
    * @param crawlerSession vsCrawler&#x7684;session,&#x91CC;&#x9762;&#x5C01;&#x88C5;&#x4E86;&#x5355;&#x4E2A;&#x7528;&#x6237;&#x4E00;&#x6B21;&#x56DE;&#x8BDD;&#x7684;&#x6240;&#x6709;&#x4FE1;&#x606F;
    * @return &#x4EE3;&#x7406;&#x5BF9;&#x8C61;
    */
   Proxy determineProxy(HttpHost host, HttpRequest request, HttpContext context, IPPool ipPool,
                        CrawlerSession crawlerSession);
} 
</code></pre></li>
</ol>
<p>&#x5F53;&#x7136;crawlerSession&#x7684;&#x7528;&#x6CD5;&#x5E76;&#x4E0D;&#x591A;&#xFF0C;&#x4F60;&#x4E00;&#x822C;&#x4F1A;&#x8FD9;&#x4E48;&#x4F7F;&#x7528;:</p>
<p>&#x4F7F;&#x7528;GET&#x65B9;&#x6CD5;&#x8BF7;&#x6C42;&#x4E00;&#x4E2A;&#x7F51;&#x9875;</p>
<pre><code>String hrml = crawlerSession.getCrawlerHttpClient().get(url.toString())
</code></pre><p> &#x4F7F;&#x7528;post&#x65B9;&#x6CD5;&#x8BF7;&#x6C42;&#x4E00;&#x4E2A;&#x7F51;&#x9875;</p>
<pre><code>String hrml = crawlerSession.getCrawlerHttpClient().post(url.toString(), Lists.newArrayList(NameValuePairBuilder
                .create()
                .addParam(&quot;key&quot;, &quot;value1&quot;)
                .addParam(&quot;key2&quot;, &quot;value2&quot;)
                .addParam(&quot;key3&quot;, &quot;value3&quot;)
                .build()));
</code></pre><p>&#x63D0;&#x4EA4;&#x4E00;&#x4E2A;JSON&#x6570;&#x636E;&#xFF1A;</p>
<pre><code> Map&lt;String,String&gt; jsonData = Maps.newHashMap();
        jsonData.put(&quot;key&quot;,&quot;value&quot;);
        jsonData.put(&quot;key2&quot;,&quot;value2&quot;);
        String html =  crawlerSession.getCrawlerHttpClient().postJSON(url.toString(),jsonData);
</code></pre><p>&#x4E0B;&#x8F7D;&#x4E00;&#x5F20;&#x56FE;&#x7247;</p>
<pre><code>        byte[] bytes = crawlerSession.getCrawlerHttpClient().getEntity(&quot;http://mtl.ttsqgs.com/uploadfile/2015/0708/20150708092409324.jpg&quot;);
        Files.write(bytes, PathResolver.commonDownloadPath(&quot;~/Desktop/beauty&quot;,&quot;http://mtl.ttsqgs.com/uploadfile/2015/0708/20150708092409324.jpg&quot;));
</code></pre><p>&#x6216;&#x7740;&#x666E;&#x901A;&#x7684;httpclient&#x7684;&#x7528;&#x6CD5;,&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x7528;&#x8D77;&#x6765;&#x9EBB;&#x70E6;&#x4E00;&#x4E9B;&#xFF0C;&#x4F46;&#x662F;post&#xFF0C;get&#xFF0C;head&#xFF0C;option&#x4F60;&#x60F3;&#x600E;&#x4E48;&#x73A9;&#x513F;&#x90FD;&#x884C;</p>
<pre><code>        HttpGet httpGet = new HttpGet(url);
        RequestConfig.Builder builder = RequestConfig.custom().setSocketTimeout(ProxyConstant.SOCKET_TIMEOUT)
                .setConnectTimeout(ProxyConstant.CONNECT_TIMEOUT)
                .setConnectionRequestTimeout(ProxyConstant.REQUEST_TIMEOUT).setRedirectsEnabled(true)
                .setCircularRedirectsAllowed(true);
        httpGet.setConfig(builder.build());
        CloseableHttpResponse closeableHttpResponse = crawlerSession.getCrawlerHttpClient().execute(httpGet);
        int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
        if(statusCode!=200){
            System.out.println(&quot;not 200&quot;);
        }
        String data = EntityUtils.toString(closeableHttpResponse.getEntity());
</code></pre><h2 id="crawresult">crawResult</h2>
<p>&#x8FD9;&#x4E2A;&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x5C31;&#x662F;&#x7528;&#x6765;&#x5B58;&#x653E;&#x6293;&#x53D6;&#x7ED3;&#x679C;&#x7684;&#xFF0C;&#x5305;&#x62EC;&#x6293;&#x53D6;&#x7ED3;&#x679C;&#x548C;&#x65B0;&#x79CD;&#x5B50;&#x4E24;&#x4E2A;&#x6570;&#x636E;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../2ji-ben-zu-jian.html" class="navigation navigation-prev " aria-label="Previous page: 2.基本组件">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="22-pipline.html" class="navigation navigation-next " aria-label="Next page: 2.2 Pipline">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"2.1 Processor","level":"1.3.1","depth":2,"next":{"title":"2.2 Pipline","level":"1.3.2","depth":2,"path":"2ji-ben-zu-jian/22-pipline.md","ref":"2ji-ben-zu-jian/22-pipline.md","articles":[]},"previous":{"title":"2.基本组件","level":"1.3","depth":1,"path":"2ji-ben-zu-jian.md","ref":"2ji-ben-zu-jian.md","articles":[{"title":"2.1 Processor","level":"1.3.1","depth":2,"path":"2ji-ben-zu-jian/processor.md","ref":"2ji-ben-zu-jian/processor.md","articles":[]},{"title":"2.2 Pipline","level":"1.3.2","depth":2,"path":"2ji-ben-zu-jian/22-pipline.md","ref":"2ji-ben-zu-jian/22-pipline.md","articles":[]},{"title":"2.3 SessionPool","level":"1.3.3","depth":2,"path":"2ji-ben-zu-jian/23-sessionpool.md","ref":"2ji-ben-zu-jian/23-sessionpool.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"2ji-ben-zu-jian/processor.md","mtime":"2017-06-24T11:06:05.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-06-25T14:04:12.299Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

